package com.spa.infrastructure.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.CouponExchangeDTO;
import com.spa.application.dto.admin.CouponExchangeExportDTO;
import com.spa.application.dto.admin.CouponExportDTO;
import com.spa.application.dto.member.CouponDTO;
import com.spa.application.query.PageQuery;
import com.spa.application.query.admin.AdminCouponExchangeQuery;
import com.spa.application.query.admin.AdminCouponQuery;
import com.spa.domain.entity.Coupon;
import com.spa.domain.entity.CouponExchange;
import com.spa.infrastructure.enums.dict.SourceEnum;
import com.spa.infrastructure.enums.dict.order.OrderStatusEnum;
import com.spa.infrastructure.repository.condition.CouponCondition;
import com.spa.infrastructure.repository.condition.CouponExchangeCondition;
import com.spa.infrastructure.repository.po.CouponExchangePO;
import com.spa.infrastructure.repository.po.CouponPO;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
@MapperConfig(unmappedTargetPolicy = ReportingPolicy.WARN)
public interface CouponMapperStruct {

    CouponMapperStruct INSTANCE = Mappers.getMapper(CouponMapperStruct.class);

    CouponCondition query2Condition(PageQuery query);
    CouponExchangeCondition query2Condition(AdminCouponExchangeQuery query);

    CouponCondition query2Condition(AdminCouponQuery query);

    Page<Coupon> po2Entity4Page(Page<CouponPO> po);

    List<Coupon> po2Entity4List(List<CouponPO> po);

    Page<CouponExchange> po2CouponExchange4Page(Page<CouponExchangePO> po);
    List<CouponExchange> po2CouponExchange4List(List<CouponExchangePO> po);

    Coupon po2Entity(CouponPO po);

    PageResult<CouponDTO> entity2Dto4Page(Page<Coupon> entity);

    PageResult<CouponExchangeDTO> entity2CouponExchangeDTO4Page(Page<CouponExchange> entity);

    @Mapping(source = "source", target = "source", qualifiedByName = "int2Enum")
    CouponExchangeDTO entity2CouponExchangeDTO(CouponExchange couponExchange);

    PageResult<com.spa.application.dto.admin.CouponDTO> entity2CouponDTO4Page(Page<Coupon> entity);

    @Mapping(source = "id", target = "orderId")
    @Mapping(source = "name", target = "serviceName")
    com.spa.application.dto.admin.CouponDTO entity2CouponDTO(Coupon coupon);

    List<CouponExchangeExportDTO> entity2CouponExchangeDTO4List(List<CouponExchange> entity);

    @Mapping(source = "source", target = "source", qualifiedByName = "int2Str")
    @Mapping(source = "groupPrice", target = "groupPrice", qualifiedByName = "fen2yuan")
    @Mapping(source = "price", target = "price", qualifiedByName = "fen2yuan")
    CouponExchangeExportDTO entity2CouponExchangeExportDTO(CouponExchange couponExchange);

    List<CouponExportDTO> entity2CouponDTO4List(List<Coupon> entity);

    @Mapping(source = "name", target = "serviceName")
    CouponExportDTO entity2CouponExportDTO(Coupon coupon);

    @Named("int2Enum")
    default SourceEnum int2Enum(int source) {
        return SourceEnum.byCode(source);
    }

    @Named("int2Str")
    default String int2Str(int source) {
        return SourceEnum.byCode(source).getDesc();
    }

    @Named("fen2yuan")
    default int fen2yuan(int fen) {
        return fen / 100;
    }

}
